/*------------------------------------------------------------------------------
*** PURPOSE: 	The following do-file generates Table 2 in the Appendix of the
				paper "Respondent biases in household surveys" by Andrew Dillon 
				and Edouard Romeo Mensah. 

*** NOTE:		Relevant globals are defined in the do-file titles "master.do"
				contained in the folder "02_do" in the replication package.
------------------------------------------------------------------------------*/


	* Appendix Table 2. Between treated balancing tests on respondent characteristics.

	descr resp_linkhead_* resp_female resp_age resp_migrant *educ*
	gen resp_linkhead_1_2=resp_linkhead_1
	replace resp_linkhead_1_2=1 if resp_linkhead_1!=1 & resp_linkhead_2==1

	#d ;
	
	global agrespvars "resp_linkhead_1 resp_linkhead_2 resp_linkhead_3
		resp_linkhead_4 resp_linkhead_5 resp_linkhead_6 resp_linkhead_7
		resp_female resp_age resp_migrant resp_finfeduc resp_feduc
		resp_feduclvl_1 resp_feduclvl_2 resp_feduclvl_3 resp_feduclvl_4" ;
	
	global agrespvars0 "resp_linkhead_1_2 resp_linkhead_3
		resp_linkhead_4 resp_linkhead_5 resp_linkhead_6 resp_linkhead_7
		resp_female resp_age resp_migrant resp_finfeduc resp_feduc
		resp_feduclvl_1 resp_feduclvl_2 resp_feduclvl_3 resp_feduclvl_4" ;
	
	la var resp_linkhead_1			"Household head" ;
	la var resp_linkhead_2			"Spouse" ;
	la var resp_linkhead_1_2		"HH head or spouse" ;
	la var resp_linkhead_3			"Child" ;
	la var resp_linkhead_4			"Grandchild" ;
	la var resp_linkhead_5			"Mother/father" ;
	la var resp_linkhead_6			"Sister/brother" ;
	la var resp_linkhead_7			"Other relative" ;
	la var resp_female				"Female respondent" ;
	la var resp_age					"Age of respondent" ;
	la var resp_migrant				"Respondent migrant" ;
	la var resp_finfeduc			"Formal or informal educ" ;
	la var resp_feduc				"Formal educ" ;
	la var resp_feduclvl_1			"No educ" ;
	la var resp_feduclvl_2			"Primary educ" ;
	la var resp_feduclvl_3			"Jun sec educ" ;
	la var resp_feduclvl_4			"Sen sec educ" ;

	global nv = wordcount("$agrespvars") ;
	disp "$nv" ;
	
	#d cr

	eststo clear
	foreach i of varlist $agrespvars0 {
		reg `i' i.treat2_rproxy if treated==1, vce(cluster village)
		qui sum `i' if e(sample) & treat1_hhead==1
		local hheadmean=r(mean)
		local hheadsd=r(sd)
		testparm i.treat2_rproxy
		local pvalue_all=r(p)
		eststo `i'_A, addscalars(pvalue_all `pvalue_all' HHheadmean `hheadmean' HHheadsd `hheadsd' )
	}
	
	

	esttab *_A using "04_output\Appendix Table 2. BalancingTest-Respondent.csv", se ///
			scalars("pvalue_all p-value: test of T2" N "Controlmean Mean of dependent variable in treatment 1 HHs" "Controlsd S.D. of dependent variable in treatment 1 HHs") sfmt(3 0 3 3) ///
			title("Appendix Table 2: Balancing test on Respondent Characteristics") ///
			mtitles("Relationship to the head of HH: household head" "Relationship to the head of HH: son/daughter" "Relationship to the head of HH: grandson/granddaughter" "Relationship to the head of HH: mother/father" "Relationship to the head of HH: sister/brother" "Relationship to the head of HH: other relative" "Female respondent" "Age of respondent" "Respondent is a migrant" "Received formal or informal education" "Received formal education" "Formal education level: none" "Formal education level: primary" "Formal education level: junior secondary" "Formal education level: senior secondary") ///
			nonotes addnotes("All standard errors are clustered at the village level. *** p<0.01; ** p<0.05; * p<0.1.") star(* 0.1 ** 0.05 *** 0.01) ///
			coeflabels(1.treat2_rproxy "T2: Random Proxy") drop(0.treat2_rproxy _cons) ///
			b(3) se(3) noobs width(25) replace
			
			estimates clear	


			